import { wxSdk } from '@/lib/WechatSdk'
import { isWechatBrowser } from '@/utils/platform'

export default {
  async onLoad() {
    this.$mpShare = {

    }

    // #ifdef H5
    // 分享内容在 wxSdk.init()之前设置
    if (isWechatBrowser() && userStore.isLogin) {
      // 获取微信配置并初始化config
      await wxSdk.getConfig()
      wxSdk.init()
    }
    // #endif
  },

  // #ifdef MP-WEIXIN
  onShareAppMessage() {
    return this.$mpShare
  },
  onShareTimeline() {
    return this.$mpShare
  },
  // #endif
  methods: {
    // #ifdef H5
    setShareData(data) {
      const { title, content, imgUrl } = data
      wxSdk.setShareData({
        title,
        desc: content,
        imgUrl,
        link: location.origin,
      })
    },
    // #endif
  },
}
